package com.linesum.code.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.ApiSelectorBuilder;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * 
 * @author chenzf
 * @date 2017年7月26日
 */
@Configuration
@EnableSwagger2
@SuppressWarnings("static-method")
public class Swagger2Configuration {

	@Bean
	public Docket createDocket() {
		Docket docket = new Docket(DocumentationType.SWAGGER_2);
		docket.apiInfo(apiInfo());
		ApiSelectorBuilder apiSelectorBuilder = docket.select();
		apiSelectorBuilder.apis(RequestHandlerSelectors.basePackage("com.linesum.code.controller.restfulapi"));
		apiSelectorBuilder.paths(PathSelectors.any());
		return apiSelectorBuilder.build();
	}

	private ApiInfo apiInfo() {
		ApiInfoBuilder apiInfoBuilder = new ApiInfoBuilder();
		apiInfoBuilder.title("Spring Boot中使用Swagger2构建RESTful APIs");
		apiInfoBuilder.description("更多Spring Boot相关文章请关注：http://blog.didispace.com/");
		apiInfoBuilder.termsOfServiceUrl("http://blog.didispace.com/");
		Contact contact = new Contact("chenzhf", "http://weibo.com/2812063534/profile?topnav=1&wvr=6",
				"15160292034@sina.cn");
		apiInfoBuilder.contact(contact).version("1.0");
		return apiInfoBuilder.build();
	}
}
